import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Lw中
 * @date 2020/12/3 19:56
 */

@Data
public class Response {

    private boolean success;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<>();

    public Response() {
    }

    public static Response ok() {
        Response response = new Response();
        response.setCode(ResponseCode.SUCCESS_CODE);
        response.setMessage("成功");
        response.setSuccess(true);
        return response;
    }

    public static Response error() {
        Response response = new Response();
        response.setCode(ResponseCode.ERROR_CODE);
        response.setMessage("失败");
        response.setSuccess(false);
        return response;
    }

    public Response message(String message) {
        this.setMessage(message);
        return this;
    }

    public Response success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public Response code(Integer code) {
        this.setCode(code);
        return this;
    }

    public Response data(Map<String, Object> hashmap) {
        this.setData(hashmap);
        return this;
    }

    public Response data(String value, Object object) {
        this.data.put(value, object);
        return this;
    }

}
